package com.guobox.movies.proxy;

import android.text.TextUtils;

import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;

/**
 * Created by xuxinlei on 2017/7/13.
 */

public class Proxy_Server {
    public static final String HEAD = "head";
    public static final String STATE = "statuscode";
    public static final String OK = "101";
    public static final String BODY = "body";

    public static JsonElement getContent(String responseJson) {
        if (!TextUtils.isEmpty(responseJson)) {
            JsonParser jsonParser = new JsonParser();
            JsonElement responseJsonElement = null;
            try {
                responseJsonElement = jsonParser.parse(responseJson);
            } catch (JsonParseException e) {
                e.printStackTrace();
                return null;
            }
            if (responseJsonElement != null) {
                if (responseJsonElement.getAsJsonObject().get(Proxy_Server.HEAD).getAsJsonObject()
                        .get(Proxy_Server.STATE).getAsString().equals(Proxy_Server.OK)) {
                    return responseJsonElement.getAsJsonObject().get(Proxy_Server.BODY);
                }
            }
        }
        return null;
    }
}
